package unimelb.filesync.common.misc;

public class ArgsValidator {
    private static final int PORT_START = 0;

    private static final int PORT_END = 65535;

    public void validatePort(String portString) {
        try {
            Integer.valueOf(portString);
        } catch (NumberFormatException e) {
            throw new IllegalArgumentException("Port is not a number");
        }

        final int port = Integer.valueOf(portString);
        if (port < PORT_START || port > PORT_END) {
            throw new IllegalArgumentException("Not valid port number");
        }
    }

    public void validateBlockSize(String blockSizeString) {
        try {
            Long.valueOf(blockSizeString);
        } catch (NumberFormatException e) {
            throw new IllegalArgumentException("Block size is not a number");
        }

        final long blockSize = Long.valueOf(blockSizeString);
        if (blockSize < 0) {
            throw new IllegalArgumentException("Block size must be greater than zero");
        }
    }
}
